﻿namespace Sidvall.IdentityManager.Security
{
    public class UserTokenManager : IUserTokenManager
    {
        #region Public Members

        #region TwoFactorProviders

        private System.Lazy<UserTokenProviderCollection> _TwoFactorProviders = new System.Lazy<UserTokenProviderCollection>(GetTwoFactorProviders);
        public UserTokenProviderCollection TwoFactorProviders
        {
            get
            {
                return _TwoFactorProviders.Value;
            }
        }

        #endregion
        #region UserTokenProvider

        public IUserTokenProvider UserTokenProvider
        {
            get
            {
                return Sidvall.IdentityManager.Security.SystemContext.Current.UserManager.UserTokenProvider as IUserTokenProvider;
            }
        }

        #endregion

        #endregion
        #region Private Members

        #region GetTwoFactorProviders

        private static UserTokenProviderCollection GetTwoFactorProviders()
        {
            var items = new UserTokenProviderCollection();
            foreach (var twoFactorProvider in Sidvall.IdentityManager.Security.SystemContext.Current.UserManager.TwoFactorProviders)
                items.Add(twoFactorProvider.Key, twoFactorProvider.Value as IUserTokenProvider);
            return items;
        }

        #endregion

        #endregion
    }
}
